package com.ys.web.user.login;

import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;

import java.util.function.Function;

public class WxOAuth2UserInfoTransformer implements Function<WxOAuth2UserInfo,LoginInfo> {
    public static final WxOAuth2UserInfoTransformer INSTANCE =
            new WxOAuth2UserInfoTransformer();
    @Override
    public LoginInfo apply(WxOAuth2UserInfo wxOAuth2UserInfo) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setUnionId(wxOAuth2UserInfo.getUnionId());
        loginInfo.setOpenId(wxOAuth2UserInfo.getOpenid());
        loginInfo.setNickName(wxOAuth2UserInfo.getNickname());
        loginInfo.setAvatarUrl(wxOAuth2UserInfo.getHeadImgUrl());
        loginInfo.setGender(wxOAuth2UserInfo.getSex());
        loginInfo.setProvince(wxOAuth2UserInfo.getProvince());
        loginInfo.setCity(wxOAuth2UserInfo.getCity());
        loginInfo.setCountry(wxOAuth2UserInfo.getCountry());
        return loginInfo;
    }
}
